<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="15" align="left" class="headmenu"><img src="image/bar_left.gif" width="15" height="42" /></td>
    <td align="left" bgcolor="#434343" class="headmenu">จัดการemailรับข้อความ-&gt;รายการทั้งหมด</td>
    <td width="15" align="left" class="headmenu"><img src="image/bar_right.gif" width="15" height="42" /></td>
  </tr>
</table>
<br />
<br />
<?

//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
	$data = array(
	"name_email"=>($_POST['name']),
	);
	insert("tb_email_receive",$data);
	?>
<SCRIPT LANGUAGE="JavaScript">alert("add email suscessfully");window.location='admin.php?mode=email.php';</script>	
<?
	//header("location:$_SERVER[PHP_SELF]");
	//exit();
}

//*** Update Condition ***//
if($_POST["hdnCmd"] == "Update")
{
	$data = array(
	"name_email"=>($_POST['namek']),
	);
	update("tb_email_receive",$data,"id = '".$_POST['id']."'");
	//header("location:$_SERVER[PHP_SELF]");
	//exit();
	?>
<SCRIPT LANGUAGE="JavaScript">alert("update email suscessfully");window.location='admin.php?mode=email.php';</script>	
<?
}

//*** Delete Condition ***//
if($_GET["Action"] == "Del")
{
	delete("tb_email_receive","id='".$_GET['CusID']."'");
	//header("location:$_SERVER[PHP_SELF]");
	//exit();
	?>
<SCRIPT LANGUAGE="JavaScript">alert("delete email suscessfully");window.location='admin.php?mode=email.php';</script>	
<?
}

$strSQL = "SELECT * FROM tb_email_receive";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form name="frmMain" method="post" action="<?=$_SERVER["PHP_SELF"];?>?mode=email.php">
  <div align="center" class="black_s13">
    <input type="hidden" name="hdnCmd" value="">
  </div>
  <table width="90%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
  <tr class="headmenu">
    <th width="80%" bgcolor="#434343" class="headmenu">email name</th>
    <th width="20%" bgcolor="#434343">จัดการ</th>
    </tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>

  <?
	if($objResult["id"] == $_GET["CusID"] and $_GET["Action"] == "Edit")
	{
  ?>
  <tr onmouseover="this.className='menu-over'" onmouseout="this.className='menu'" class="menu">
    <td bgcolor="#FFFFFF" class="headmenu"><div align="center">
		<input type="text" name="namek" size="40" value="<?=$objResult["name_email"];?>">
		<input type="hidden" name="id" size="5" value="<?=$objResult["id"];?>">
	</div></td>
    <td align="right" bgcolor="#FFFFFF"><div align="center">
      <input name="btnAdd" type="button" id="btnUpdate" value="Update" OnClick="frmMain.hdnCmd.value='Update';frmMain.submit();">
      &nbsp;
	  <input name="btnAdd" type="button" id="btnCancel" value="Cancel" OnClick="window.location='<?=$_SERVER["PHP_SELF"];?>?mode=email.php';">
    </div></td>
  </tr>
  <?
	}
  else
	{
  ?>
  <tr onmouseover="this.className='menu-over'" onmouseout="this.className='menu'" class="menu">
    <td bgcolor="#FFFFFF" class="darkgray13"><div align="center"><?=$objResult["name_email"];?></div></td>
    <td align="center" bgcolor="#FFFFFF"><a  href="admin.php?mode=email.php&Action=Edit&CusID=<?=$objResult["id"];?>" class="black_s13"><img src="image/b_edit.gif" border="0" />&nbsp;</a><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?mode=email.php&Action=Del&CusID=<?=$objResult["id"];?>';}" >&nbsp;&nbsp;&nbsp;<img src="image/delete.gif" border="0" /></a></td>
	</tr>
  <?
	}
  ?>
<?
}
?>
  <tr onmouseover="this.className='menu-over'" onmouseout="this.className='menu'" class="menu">
    <td bgcolor="#FFFFFF" class="headmenu"><div align="center"><input type="text" name="name" size="40">
    </div></td>
    <td align="right" bgcolor="#FFFFFF"><div align="center">
      <input name="btnAdd" type="button" id="btnAdd" value="Add" OnClick="frmMain.hdnCmd.value='Add';frmMain.submit();">
    </div></td>
  </tr>
</table>
</form>

</body>
</html>
